package io;

import atom.UnaryAtom;
import formula.BinaryFormula;
import formula.Formula;
import formula.UnaryFormula;
import io.InputFrame;
import literal.UnaryLiteral;
import sign.FormulaSign;

import javax.swing.*;
import java.awt.*;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;


public class OutFrame {
    public OutFrame(){
        // 创建 JFrame
        JFrame frame = new JFrame("Console Output");
        //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 400);
        frame.setLocationRelativeTo(null);

        // 创建 JTextArea 并设置不可编辑
        JTextArea textArea = new JTextArea();
        textArea.setEditable(false);
        Font font = new Font("Serif", Font.BOLD, 20);//设置输出字体大小
        textArea.setFont(font);

        // 将 JTextArea 放到 JScrollPane 中
        JScrollPane scrollPane = new JScrollPane(textArea);
        frame.add(scrollPane);

        // 显示 JFrame
        frame.setVisible(true);

        // 重定向 System.out 到 JTextArea
        PrintStream printStream = new PrintStream(new OutputStream() {
            @Override
            public void write(int b) {
                // 将数据写入 JTextArea
                textArea.append(String.valueOf((char) b));
                textArea.setCaretPosition(textArea.getDocument().getLength()); // 自动滚动到最后
            }
        });

        System.setOut(printStream);
        System.setErr(printStream);

        D1_D2Test();
    }
    public static void main(String[] args) {


        // 测试输出
        //System.out.println("Hello, this is a test message!");
        //System.out.println("This is displayed in the JTextArea instead of the terminal.");

       D1_D2Test();


    }

    public static void D1_D2Test(){ //rule D1 +rule D2
        UnaryFormula p=new UnaryFormula(new UnaryLiteral(new UnaryAtom("p"),false));
        Formula q=new UnaryFormula(new UnaryLiteral(new UnaryAtom("q"),false));
        Formula l=new UnaryFormula(new UnaryLiteral(new UnaryAtom("l"),false));
        BinaryFormula f1=new BinaryFormula(FormulaSign.ANY,q,l);
        BinaryFormula f2=new BinaryFormula(FormulaSign.EXIST,p,q);
        BinaryFormula f3=new BinaryFormula(FormulaSign.ANY,p,q);

        Formula conclusion=new BinaryFormula(FormulaSign.EXIST,q,l);//最终结论
        ArrayList<Formula> formulas=new ArrayList<>();
        formulas.add(f1);
        formulas.add(f2);
        formulas.add(f3);
        //System.out.println(Solve.solve(formulas,conclusion));
    }

}
